package zxq.rollcall.course.service.impl;

import zxq.rollcall.course.entity.SystemCourseTableEntity;
import zxq.rollcall.course.mapper.SystemCourseTableDao;
import zxq.rollcall.course.service.MPSystemCourseTableService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * <p>
 * 课程表 服务实现类
 * </p>
 *
 * @author Yanghu
 * @since 2020-01-22
 */
@Service
public class SystemCourseTableServiceDiy extends ServiceImpl<SystemCourseTableDao, SystemCourseTableEntity> implements MPSystemCourseTableService {



    
    @Override
    public Integer getDayOfWeek() {
        Date today = new Date();
        Calendar c = Calendar.getInstance();
        c.setTime(today);
        int weekday = c.get(Calendar.DAY_OF_WEEK);
        return weekday;
    }



    @Override
    public Boolean startSign(Integer courseId) {
        SystemCourseTableEntity courseTableEntity = getById(courseId);
        Boolean canSign = courseTableEntity.getCanSign();
        if(canSign) {
            return false;
        }
        courseTableEntity.setCanSign(true);
        return updateById(courseTableEntity);
    }

    @Override
    public Boolean stopSign(Integer courseId) {
        SystemCourseTableEntity courseTableEntity = getById(courseId);
        Boolean canSign = courseTableEntity.getCanSign();
        if(!canSign) {
            return false;
        }
        courseTableEntity.setCanSign(false);
        return updateById(courseTableEntity);
    }

    @Override
    public Integer getClassId(Integer courseId) {
        return getById(courseId).getClassesId();
    }


}
